//
//  WeiDuZhanShi_ViewController.m
//  iBook
//
//  Created by apple on 15/1/20.
//  Copyright (c) 2015年 wikiflyer. All rights reserved.
//

#import "WeiDuZhanShi_ViewController.h"
#import "ShuJiXiangQing_ViewController.h"
#import "JingXuan_FenLei_ViewController.h"

@interface WeiDuZhanShi_ViewController ()

@end

@implementation WeiDuZhanShi_ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    UIView *view = [UIView new];
    view.backgroundColor = [UIColor clearColor];
    [_myTableV setTableFooterView:view];
    [_myTableV setBackgroundColor:[UIColor whiteColor]];
    [self.view addSubview:_myTableV];
    
    [self goLineFenLei];
    
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

#pragma mark - UITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return _arrayFenLei.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    //    FeatureTableViewCell *cell = [FeatureTableViewCell CellWithTableView:tableView];
    //    [cell initData:indexPath];
    //    cell.cellDelegate = self;
    //    cell.showDelegate = self;
    NSString * str1=@"123";
    JingXuanShouYe_TableViewCell * cell=[tableView dequeueReusableCellWithIdentifier:str1];
    if (!cell) {
        cell=[JingXuanShouYe_TableViewCell homeCellCellOwner:self];
    }
    cell.selectionStyle=UITableViewCellSelectionStyleNone;
    if (_arrayShuJi.count>0) {
        [cell initWithSome:_arrayShuJi[indexPath.row] thetitle:_arrayFenLei[indexPath.row]];
        cell.delegate=self;
    }
    return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    //取消选中状态
    [tableView deselectRowAtIndexPath:indexPath animated:NO];
}
#pragma mark - UITableViewDelegate
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 245;
}

#pragma mark - 网络请求 - - 分类
-(void)goLineFenLei{
    NSMutableDictionary *dic=[[NSMutableDictionary alloc]init];
    [dic setObject:_strWeiDuID forKey:@"aid"];
    [self getFenLei:@"http://www.xdoc.cn/json/LoadHelixInfo.aspx?"andDictionary:dic];
}
-(void)getFenLei:(NSString *)url andDictionary:(NSDictionary *)yourDictionary{
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"application/json", @"text/json", @"text/javascript", @"text/plain",@"text/html",nil];
    [manager GET:url parameters:yourDictionary success:^(AFHTTPRequestOperation *operation, id responseObject) {
        [self initWithDataSFenLei:responseObject];
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        NSLog(@"%@",error);
    }];
}
-(void)initWithDataSFenLei:(NSDictionary *)theDic{
    //    NSLog(@" - - - all = %@",theDic);
    _arrayFenLei=[[NSMutableArray alloc] init];
    [_arrayFenLei addObjectsFromArray:[theDic objectForKey:@"his"]];
    [_myTableV reloadData];
    _arrayShuJi=[[NSMutableArray alloc] init];
    for (int a=0; a<_arrayFenLei.count; a++) {
        NSMutableArray * array=[[NSMutableArray alloc] init];
        [_arrayShuJi addObject:array];
        [self goLineShuJi:[_arrayFenLei[a] objectForKey:@"hid"] theIndex:a];
    }
}
#pragma mark - 网络请求 - - 分类下所有的书籍
-(void)goLineShuJi:(NSString *)theType theIndex:(int)theIndex{
    NSMutableDictionary *dic=[[NSMutableDictionary alloc]init];
    [dic setObject:theType forKey:@"hid"];
    [self getShuJi:@"http://www.xdoc.cn/json/LoadOliveInfo.aspx?"andDictionary:dic theIndex:theIndex];
}
-(void)getShuJi:(NSString *)url andDictionary:(NSDictionary *)yourDictionary theIndex:(int)theIndex{
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"application/json", @"text/json", @"text/javascript", @"text/plain",@"text/html",nil];
    [manager GET:url parameters:yourDictionary success:^(AFHTTPRequestOperation *operation, id responseObject) {
        [self initWithDataSShuJi:responseObject theIndex:theIndex];
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        NSLog(@"%@",error);
    }];
}
-(void)initWithDataSShuJi:(NSDictionary *)theDic theIndex:(int)theIndex{
    //    NSLog(@" - - - all = %@",theDic);
    NSMutableArray * array=[[NSMutableArray alloc] initWithArray:[theDic objectForKey:@"ois"]];
    _arrayShuJi[theIndex]=array;
    [_myTableV reloadData];
}

#pragma mark - JingXuanShouYe_TableViewCell_Detegate
-(void)JingXuanShouYe_TableViewCell_Detegate:(JingXuanShouYe_TableViewCell *)theCell theID:(NSString *)theID{
    NSLog(@"选中的id %@",theID);
    ShuJiXiangQing_ViewController * shujiV=[[ShuJiXiangQing_ViewController alloc] init];
    shujiV.strIDJieShou=theID;
    [self.navigationController pushViewController:shujiV animated:YES];
}

-(void)JingXuanShouYe_TableViewCell_DetegateQuanBu:(JingXuanShouYe_TableViewCell *)theCell theID:(NSString *)theID{
    NSLog(@"全部显示");
    JingXuan_FenLei_ViewController * jingV=[[JingXuan_FenLei_ViewController alloc] init];
    jingV.strIDJieShou=theID;
    [self.navigationController pushViewController:jingV animated:YES];
}

@end
